package com.xihuanjun.sdk.dao;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.xihuanjun.sdk.entity.JSTGoodsStock;
import com.xihuanjun.sdk.entity.JSTInout;
import com.xihuanjun.sdk.entity.JSTPageData;
import com.xihuanjun.sdk.enums.JSTMethod;
import com.xihuanjun.sdk.util.JsonUtils;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Copyright (C), 2024-09-27
 * FileName: JSTStockDao
 * Author:   溪浣君
 * Date:     2024-09-27 15:37
 * Description:
 */
@Component
public class JSTStockDao extends  BaseDao{
    public List<JSTGoodsStock> getStock(String start, String end) throws IOException {

        /*
        {
  "page_index": 1,
  "page_size": 100,
"modified_begin": "2023-05-25 00:00:06",
  "modified_end": "2023-05-30 00:00:06"
}
         */
        int pageIndex=1;
        List<JSTGoodsStock> list=new ArrayList<>();
        HashMap hashMap=new HashMap();
        hashMap.put("page_size",100);
        hashMap.put("modified_begin",start);
        hashMap.put("modified_end",end);
        List<JSTGoodsStock> jstGoodsStocks;
        while(true) {
            hashMap.put("page_index",pageIndex);
            jstGoodsStocks= this.jstListQuery(hashMap, JSTMethod.JST_INVENTORY_QUERY, new TypeReference<List<JSTGoodsStock>>() {});
            pageIndex++;
            if(jstGoodsStocks!=null){
                if(jstGoodsStocks.size()>0){//有数据
                    list.addAll(jstGoodsStocks);
                }else{
                    break;
                }
                if(jstGoodsStocks.size()<100){
                    break;
                }
            }
        }
        return list;
    }

}
